<template>
  <el-container v-if="power=='大人'||power=='老人'||power=='儿童'">
    <el-header>
      <div class="logo">
        <h1>happy family</h1>
        <div class="rightfloat">
          <!-- 点击头像设置 -->
          <div
            :style="{
              float: 'left',
              width: '30px',
              height: '38px',
              color: 'white',
            }"
          >
            <div
              @click="toMassageaaa"
              v-if="aa"
              :style="{
                cursor: 'pointer',
                width: '20px',
                height: '20px',
                color: 'white',
                backgroundColor: 'red',
                marginTop: '9px',
                borderRadius: '8px',
                textAlign: 'center',
              }"
            >
              {{ aa }}
            </div>
          </div>
          <i class="avatar-uploader" @click="pathSet">
            <img :src="img" />
          </i>
          <!-- <el-upload class="avatar-uploader" action="http://localhost:8082" :show-file-list="false" :on-change="handleAvatarSuccess"
            :before-upload="beforeAvatarUpload" :headers="headers" name="file">
            <img :src="imageUrl">
          </el-upload> -->

          <!-- <el-popover  action="http://localhost:8082" on-change="handleAvatarSuccess"
            :before-upload="beforeAvatarUpload">
          </el-popover> -->

          <el-popover placement="top" width="160" v-model="visible">
            <p>您确定要退出吗？</p>
            <div style="text-align: right; margin: 0">
              <el-button size="mini" type="text" @click="visible = false"
                >取消</el-button
              >
              <el-button type="primary" size="mini" @click="ToLogin"
                >确定</el-button
              >
            </div>
            <i class="el-icon-circle-close" slot="reference"></i>
          </el-popover>
        </div>
      </div>
    </el-header>
    <el-container>
      <el-aside width="200px">
        <el-menu
          :router="true"
          default-active="/happyhome/user"
          class="el-menu-vertical-demo"
        >
          <!-- <el-menu-item index="/happyhome/user">
            <i class="el-icon-apple"></i>
            <span slot="title">Zing</span>
          </el-menu-item> -->
          <el-menu-item
            index="/happyhome/home"
            v-if="power == '大人' || power == '老人' || power == '儿童'"
          >
            <i class="el-icon-house"></i>
            <span slot="title">Home</span>
          </el-menu-item>
          <el-menu-item
            index="/happyhome/live/cook"
            v-if="power == '大人' || power == '老人' || power == '儿童'"
          >
            <i class="el-icon-headset"></i>
            <span slot="title">Live</span>
          </el-menu-item>
          <el-menu-item
            index="/happyhome/work"
            v-if="power == '大人' || power == '老人'"
          >
            <i class="el-icon-files"></i>
            <span slot="title">work</span>
          </el-menu-item>
          <el-menu-item
            index="/happyhome/leisure"
            v-if="power == '大人' || power == '老人' || power == '儿童'"
          >
            <i class="el-icon-basketball"></i>
            <span slot="title">leisure</span>
          </el-menu-item>
        </el-menu>
      </el-aside>
      <el-main>
        <!-- <div class="head">
<div class="heads"><p>记事本</p></div>
<div class="heads"><p>收入信息</p></div>
<div class="heads"><p>工作打卡</p></div>
<div class="heads"><p>xxx</p></div>
</div><hr> -->
        <RouterView></RouterView>
      </el-main>
    </el-container>
  </el-container>
</template>
<style scoped lang="less">
#app,
body,
html,
.el-container {
  height: 100%;
  margin: 0;
  font-family: "Helvetica Neue", Helvetica, "PingFang SC", "Hiragino Sans GB",
    "Microsoft YaHei", "微软雅黑", Arial, sans-serif;
}

.el-header {
  background-color: rgb(255, 233, 192);
  color: #333;
  line-height: 23px;

  .logo {
    h1 {
      cursor: pointer;
      float: left;
    }

    .rightfloat {
      box-sizing: border-box;
      padding-left: 20px;
      float: right;
      margin-top: 15px;
      width: 140px;

      .el-icon-circle-close {
        font-size: 26px;
        padding-top: 1px;
      }

      .item {
        cursor: pointer;
      }

      .el-icon-bell {
        margin-top: 5px;
        float: left;
        font-size: 28px;
        margin-left: 10px;
        margin-right: 13px;
      }

      i {
        font-size: 24px;
        cursor: pointer;
        margin-top: 5px;
      }

      img {
        width: 30px;
        border-radius: 50%;
        // margin-left: 20px;
        // margin-right: 15px;
        position: relative;
        top: -3px;
        cursor: pointer;
        // vertical-align:middle
      }
    }
  }
}

.el-aside {
  color: #333;
  text-align: center;
  line-height: 200px;

  .el-menu-item {
    padding-right: 20px;
    text-align: left;
    i {
      float: left;
      line-height: 56px;
      margin-left: 40px;
      margin-right: 15px;
    }
  }

  width: 200px !important;

  .el-menu {
    height: 100%;
    background-color: rgb(252, 244, 223);
  }
}

.el-main {
  background-color: rgb(255, 255, 255);
  color: #333;
  text-align: center;
  padding: 0;

  .head:after {
    content: "";
    display: block;
    clear: both;
  }

  .head {
    // width: 100%;
    height: 70px;

    .heads {
      float: left;

      p {
        line-height: 40px;
        background-color: rgb(255, 255, 255);
        margin-left: 18px;
        border: 1px solid #949494;
        border-top: none;
        box-shadow: 0px 6px 6px #9a9595;
        width: 100px;
        cursor: pointer;
      }
    }
  }
}

body > .el-container {
  margin-bottom: 40px;
}

.el-container:nth-child(5) .el-aside,
.el-container:nth-child(6) .el-aside {
  line-height: 260px;
}

.el-container:nth-child(7) .el-aside {
  line-height: 320px;
}

.avatar-uploader {
  width: 40px;
  float: left;
}

.avatar-uploader .el-upload {
  border: 1px dashed #d9d9d9;
  width: 40px;
  display: inline-block;
  border-radius: 6px;
  cursor: pointer;
  position: relative;
  overflow: hidden;
}

.avatar-uploader .el-upload:hover {
  border-color: #409eff;
}

.avatar-uploader-icon {
  font-size: 28px;
  color: #8c939d;
  width: 178px;
  height: 178px;
  // line-height: 178px;
  text-align: center;
}

.avatar {
  width: 178px;
  height: 178px;
  display: block;
}
</style>
<script>
import { computed } from "vue";
import axios from "axios";
// axios.defaults.baseURL = 'http://localhost:8082';
export default {
  data() {
    return {
      isCollapse: true,
      visible: false,
      power: "",
      img: "",
      // imageUrl: require('../assets/image/zlj/1.jpg'),
      // headers: {
      //   'Content-Type': 'multipart/form-data'
      // },
      // fileList: []
    };
  },
  mounted() {
    let power=sessionStorage.getItem('userType')
    let id=sessionStorage.getItem('userId')
    axios({url:'/dbdata/userTalk/'+id+''}).then(({data})=>{
      this.img=data.avatar;
    })
    if(power){
 this.power=power;
    }else{
       this.$router.push("/");
    }
  },
  methods: {
    toMassageaaa() {
      this.$store.state.massageAll = 0;
      this.$router.push("/happyhome/home/FriendChata");
    },
    path() {
      window.location.href = "/happyhome/home/FriendChata";
    },
    pathSet() {
      window.location.href = "/happyhome/home/PersonSet";
    },
    ToLogin() {
      this.visible = false;
      window.location.href = "/";
    },
    // handleAvatarSuccess(res, file) {
    //   // console.log(111);
    //   // let fileReader = new FileReader()
    //   // console.log(fileReader);
    //   // axios.post('http://localhost:8082/upload', param).then((res) => {
    //   //   console.log(111);
    //   //   console.log(111, res);
    //   //   this.imageUrl = res.path;
    //   // })
    //   console.log(111,res);
    //   console.log(112,file);
    // },
    // beforeAvatarUpload(file) {
    //   const isJPG = file.type === 'image/jpeg' || 'image/png';
    //   const isLt30M = file.size / 1024 / 1024 < 30;

    //   if (!isJPG) {
    //     this.$message.error('上传头像图片只能是 JPG 或者png格式!');
    //   }
    //   if (!isLt30M) {
    //     this.$message.error('上传头像图片大小不能超过 30MB!');
    //   }
    //   return isJPG && isLt30M;
    // },
    open() {
      axios({
        url: "/dbdata/notepad",
      }).then((res) => {
        res.data.forEach((v, i) => {
          if (v.distance < 3) {
            this.$alert(
              "事件：" + v.eventname + "  " + "内容：" + v.content,
              "今日待办",
              {
                confirmButtonText: "确定",
                callback: (action) => {},
              }
            );
          }
        });
      });
    },
  },
  computed: {
    aa() {
      return this.$store.state.massageAll;
    },
  },
};
</script>
